package com.quanquan.parking.dao;

import com.quanquan.parking.entity.UserCar;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName:UserCarReository
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/4/2 15:08
 * @Version 1.0
 */
public interface UserCarReository extends JpaRepository<UserCar, String> {

    /**
     * 通过userId查找绑定的车牌
     *
     * @return
     */
    @Query(value = "select * from oo_user_car where mobile = ?1 and status_remove = 0", nativeQuery = true)
    List<UserCar> findByMobile(String mobile);

    /**
     * 通过phone和车牌查找记录
     *
     * @return
     */
    @Query(value = "select * from oo_user_car where mobile = ?1 and car_number = ?2 and status_remove = 0", nativeQuery = true)
    UserCar findByMobileAndCarNumber(String mobile,String carNumber);

    @Query(value = "select * from oo_user_car where mobile = ?1 and car_number = ?2", nativeQuery = true)
    UserCar findByMobileAndCarNumberAndStatusRemove(String mobile,String carNumber);

    @Query(value = "select * from oo_user_car where car_number = ?1", nativeQuery = true)
    List<UserCar> findByCarNumber(String carNumber);

}
